<template>
  <div id="rules_id">
    <!-- 上层注释以及添加按钮 -->
    <div class="rules_id_top">
      <div class="rules_id_left">
        注：<br />
        1.增加的新栏目为当前栏目的下一行<br />
        2.修改完的栏目一行需要后提交审批才能生效
      </div>
      <div class="rules_id_right">
        <el-button round @click="zengjia">增加</el-button>
      </div>
    </div>
    <!-- 下层渲表格 -->
    <el-table
      :data="rules_list"
      style="width: 100%; margin-bottom: 20px; margin-top: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="specsname" label="规格名称"> </el-table-column>
      <el-table-column prop="attrs" label="规格参数" v-slot="shuju">
        <el-button
          size="mini"
          type="success"
          v-for="attr in shuju.row.attrs"
          :key="attr.id"
          >{{ attr }}</el-button
        >
      </el-table-column>
      <el-table-column label="状态" prop="status" v-slot="$s" width="155">
        <template>
          <el-button round size="mini" type="success" v-if="$s.row.status == 1">
            已启用
          </el-button>
        </template>
        <template>
          <el-button round size="mini" type="danger" v-if="$s.row.status == 0">
            已禁用
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" v-slot="shuju">
        <template>
          <el-button
            round
            class="xiugai"
            type="warning"
            size="mini"
            @click="xiugai(shuju.row)"
            >修改</el-button
          >
        </template>
        <template>
          <el-button
            round
            class="shanchu"
            type="danger"
            size="mini"
            @click="shanchu(shuju.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="zongshu"
      :page-size="size"
      style="text-align: center"
      @current-change="currentchange"
    >
    </el-pagination>
    <addrules
      :isShow="isShow"
      @rulesadd="rulesadd"
      ref="addrules_gaibian"
    ></addrules>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import addrules from "../components/addrules.vue";
export default {
  data() {
    return {
      page: 1,
      total: 0,
      size: 1,
      isShow: { sta: false },
    };
  },
  created() {
    this.RulesActions();
    this.RulesZongshu();
  },
  computed: {
    ...mapState({
      rules_list: (state) => state.RulesStore.rules_list,
      zongshu: (state) => state.RulesStore.zongshu,
    }),
  },
  methods: {
    shanchu(id) {
      this.$http.post("/api/specsdelete", { id }).then((res) => {
        if (res.code == 200) {
          this.page

          
          alert("删除成功");
          this.RulesZongshu();
          this.RulesActions();
          
        }
        
      });
    },
    xiugai(obj) {
      this.isShow.sta = true;
      this.$refs.addrules_gaibian.addrules_xiugai(obj);
    },
    rulesadd() {
      this.RulesZongshu();
      this.RulesActions();
    },
    zengjia() {
      this.isShow.sta = true;
    },
    currentchange(page) {
      this.page = page;
      this.RulesActions({ page: this.page, size: this.size });
    },
    ...mapActions("RulesStore", ["RulesActions", "RulesZongshu"]),
  },
  components: {
    addrules,
  },
};
</script>

<style>
#rules_id .rules_id_top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#rules_id .rules_id_top .rules_id_left {
  font-size: 12px;
  color: #c4c4c4;
}
#rules_id .rules_id_top .rules_id_right button {
  height: 10px;
  line-height: 2px;
  font-size: 12px;
  color: #ffa998;
}
</style>